//package com.etrans.web.gps.business.report.controller;
//
//import java.text.ParseException;
//import java.text.SimpleDateFormat;
//import java.util.ArrayList;
//import java.util.Date;
//import java.util.HashMap;
//import java.util.List;
//import java.util.Map;
//
//import javax.servlet.http.HttpServletRequest;
//import javax.servlet.http.HttpServletResponse;
//
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.stereotype.Controller;
//import org.springframework.ui.Model;
//import org.springframework.web.bind.annotation.RequestMapping;
//import org.springframework.web.bind.annotation.ResponseBody;
//
//import com.alibaba.fastjson.JSON;
//import com.alibaba.fastjson.JSONArray;
//import com.alibaba.fastjson.JSONObject;
//import com.etrans.web.gps.base.controller.BaseController;
//import com.etrans.web.gps.business.alarm.domain.AlarmPenddingInfo;
//import com.etrans.web.gps.business.gis.domain.SubsectionVO;
//import com.etrans.web.gps.business.report.domain.AnalysisVo;
//import com.etrans.web.gps.business.report.domain.HistoryPicVO;
//import com.etrans.web.gps.business.report.domain.VehicleRunningVo;
//import com.etrans.web.gps.business.report.service.AlarmDailyDetailService;
//import com.etrans.web.gps.business.report.service.HisPicService;
//import com.etrans.web.gps.business.report.service.VehicleRunningService;
//import com.etrans.web.gps.business.system.domain.SysUser;
//import com.etrans.web.gps.util.DateUtil;
//import com.etrans.web.gps.util.StringUtils;
//import com.etrans.web.gps.util.TimeFormatUtils;
//import com.etrans.web.gps.util.grid.FlexiGridUtil;
//import com.etrans.web.gps.util.grid.ParamMap;
///**
// * 车辆行驶分析控制层
// * @author tanhang
// *
// */
//
//@Controller
//@RequestMapping("/report/vehicleRunning/*")
//public class VehicleRunningController extends BaseController{
//	
//	@Autowired
//	private VehicleRunningService vehicleRunningService;
//	
//	@Autowired
//	private AlarmDailyDetailService alarmDailyDetailService;
//	
//	@Autowired
//	private HisPicService hisPicService;
//	
//	/**
//	 * 进入车辆行驶分析页面
//	 */
//	@RequestMapping(value = "vehicleRunning.html")
//	public String loadVehicleRunning(Model model){
//		return "views/business/report/vehicleRunning";
//	}
//	
//	/**
//	 * 车辆行驶分析
//	 * @param request
//	 * @throws ParseException 
//	 */
//	@RequestMapping(value="getVehicleRunning.html")
//	@ResponseBody
//	public VehicleRunningVo getVehicleRunning() throws ParseException{
//		HashMap<String,Object> paramMap=getReqParameters();  
//	    VehicleRunningVo vehicleRunning=new VehicleRunningVo();
//	    List<AnalysisVo> vehicleRunningList=vehicleRunningService.getVehicleRunning(paramMap);
//	    if(vehicleRunningList!=null &&vehicleRunningList.size()>0){
//    		for(int i=0;i<vehicleRunningList.size();i++){
//    			AnalysisVo vo = vehicleRunningList.get(i);
//    			List<HistoryPicVO> list = hisPicService.queryPicListByVehicleId(paramMap.get("vehicleId").toString(),DateUtil.getStandardDateStr(DateUtil.getStrToDate(paramMap.get("startTime").toString()))+" 00:00:00",DateUtil.getStandardDateStr(DateUtil.getStrToDate(paramMap.get("endTime").toString()))+" 23:59:59");
//    			if(null!=list){
//    				vo.setPicCount(list.size());
//    			}else{
//    				vo.setPicCount(0);
//    			}
//    		}
//    	}
//	    List<String> listDate = new ArrayList<String>();
//	    try  
//	    {  
//	        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd ");  
//	        Date sdate = sdf.parse(paramMap.get("startTime").toString()); 
//	        Date edate = sdf.parse(paramMap.get("endTime").toString()); 
//	        listDate=DateUtil.getBetweenDates(sdate, edate);
//	    }  
//	    catch (Exception e)  
//	    {  
//	        System.out.println(e.getMessage());  
//	    } 
//	    int n=0;
//	    List<AnalysisVo> vehicleRunningDetailsList=vehicleRunningService.getVehicleRunningDetails(paramMap);
//	    List<AnalysisVo> vehicleRunningDetailsListResult=new ArrayList<AnalysisVo>();
//	    if(vehicleRunningDetailsList!=null &&vehicleRunningDetailsList.size()>0){
//	    	if(listDate.size()==vehicleRunningDetailsList.size()){
//	    		for(int i=0;i<vehicleRunningDetailsList.size();i++){
//	    			AnalysisVo vo = vehicleRunningDetailsList.get(i);
//	    			List<HistoryPicVO> list = hisPicService.queryPicListByVehicleId(vo.getVehicleId()+"",vo.getAnalyseDate()+" 00:00:00",vo.getAnalyseDate()+" 23:59:59");
//	    			if(null!=list){
//	    				vo.setPicCount(list.size());
//	    			}else{
//	    				vo.setPicCount(0);
//	    			}
//	    			vehicleRunningDetailsListResult.add(vo);
//	    		}
//	    	}else{
//	    		for(int i=0;i<vehicleRunningDetailsList.size();i++){
//	    			AnalysisVo vo = vehicleRunningDetailsList.get(i);
//	    			if(listDate.get(n).equals(vo.getAnalyseDate())){
//	    				
//	    				List<HistoryPicVO> list = hisPicService.queryPicListByVehicleId(vo.getVehicleId()+"",vo.getAnalyseDate()+" 00:00:00",vo.getAnalyseDate()+" 23:59:59");
//		    			if(null!=list){
//		    				vo.setPicCount(list.size());
//		    			}else{
//		    				vo.setPicCount(0);
//		    			}
//		    			n++;
//		    			vehicleRunningDetailsListResult.add(vo);
//	    			}else{
//
//	    				
//	    				while(!listDate.get(n).equals(vo.getAnalyseDate())){
//	    					AnalysisVo temp1=new AnalysisVo();
//	    					temp1.setAlarmCount(0);
//	    					temp1.setAlarmkindId(0);
//	    					temp1.setStartTime("2016-01-01 00:00:00");
//	    					temp1.setEndTime("2016-01-01 00:00:00");
//	    					temp1.setConditionSpeed(0);
//	    					temp1.setDuration(0);
//				    		temp1.setDealed(0);
//				    		temp1.setPicCount(0);
//				    		temp1.setTotalMileage(0);
//				    		temp1.setTotalNightDriving(0);
//				    		temp1.setTotalVehicleTired(0);
//				    		temp1.setTotalRoadOverspeed(0);
//				    		temp1.setTotalVehicleSpeed(0);
//				    		temp1.setAnalyseDate(listDate.get(n));
//				    		n++;
//		    				vehicleRunningDetailsListResult.add(temp1);
//		    				if(n==listDate.size()){
//		    					break;
//		    				}
//	    				}
//	    				
//	    				if(listDate.get(n).equals(vo.getAnalyseDate())){
//	    					List<HistoryPicVO> list = hisPicService.queryPicListByVehicleId(vo.getVehicleId()+"",vo.getAnalyseDate()+" 00:00:00",vo.getAnalyseDate()+" 23:59:59");
//			    			if(null!=list){
//			    				vo.setPicCount(list.size());
//			    			}else{
//			    				vo.setPicCount(0);
//			    			}
//			    			n++;
//			    			vehicleRunningDetailsListResult.add(vo);
//	    				}
//	    			}
//	    			
//	    			
//	    		}
//	    		
//	    		if(vehicleRunningDetailsListResult.size()!=listDate.size()){
//	    			for(int m=vehicleRunningDetailsListResult.size();m<listDate.size();m++){
//	    				AnalysisVo temp=new AnalysisVo();
//			    		temp.setAlarmCount(0);
//			    		temp.setAlarmkindId(0);
//			    		temp.setStartTime("2016-01-01 00:00:00");
//			    		temp.setEndTime("2016-01-01 00:00:00");
//			    		temp.setConditionSpeed(0);
//			    		temp.setDuration(0);
//			    		temp.setDealed(0);
//			    		temp.setPicCount(0);
//			    		temp.setTotalMileage(0);
//			    		temp.setTotalNightDriving(0);
//			    		temp.setTotalVehicleTired(0);
//			    		temp.setTotalRoadOverspeed(0);
//			    		temp.setTotalVehicleSpeed(0);
//			    		temp.setAnalyseDate(listDate.get(m));
//	    				vehicleRunningDetailsListResult.add(temp);
//	    			}
//	    		}
//	    	}
//	    	
//	    	
//    		
//    	}else{
//    		if(listDate.size()>0){
//    			for(int m=0;m<listDate.size();m++){
//    				AnalysisVo temp=new AnalysisVo();
//		    		temp.setAlarmCount(0);
//		    		temp.setAlarmkindId(0);
//		    		temp.setStartTime("2016-01-01 00:00:00");
//		    		temp.setEndTime("2016-01-01 00:00:00");
//		    		temp.setConditionSpeed(0);
//		    		temp.setDuration(0);
//		    		temp.setDealed(0);
//		    		temp.setPicCount(0);
//		    		temp.setTotalMileage(0);
//		    		temp.setTotalNightDriving(0);
//		    		temp.setTotalVehicleTired(0);
//		    		temp.setTotalRoadOverspeed(0);
//		    		temp.setTotalVehicleSpeed(0);
//		    		temp.setAnalyseDate(listDate.get(m));
//    				vehicleRunningDetailsListResult.add(temp);
//    			}
//    		}
//    	}
//	    
//		vehicleRunning.setListVehicleRunning(vehicleRunningList);
//		vehicleRunning.setListVehicleRunningDetails(vehicleRunningDetailsListResult);
//		return vehicleRunning; 
//	}
//	
//	/**
//	 * 获取报警详情
//	 * @return
//	 * @throws ParseException 
//	 */
//	@RequestMapping(value="getVehicleAlarmDetails.html")
//	@ResponseBody
//	public VehicleRunningVo getVehicleAlarmDetails() throws ParseException{
//		HashMap<String,Object> paramMap=getReqParameters(); 
//		VehicleRunningVo vehicleRunningVo=new VehicleRunningVo();
//		List listVehicleAlarmDetails =new ArrayList<>(); 
//
//		String paramsGrid=(String)paramMap.get("paramsGrid");
//		JSONObject obj=JSONObject.parseObject(paramsGrid);
//		JSONArray arr=obj.getJSONArray("whereparams");
//		if(arr==null||arr.size()==0){
//			return vehicleRunningVo;
//		}
//		JSONObject paramObj= (JSONObject) arr.get(0);
//		if(paramObj==null||paramObj.size()==0){
//			return vehicleRunningVo;
//		}
//		String alarmType=paramObj.getString("alarmType");
//		if(!StringUtils.isEmpty(alarmType)){
//			HashMap<String,Object> whereParam=new HashMap<>();
//			whereParam.put("starDateTime", (String)paramObj.getString("starDateTime"));
//			whereParam.put("endDateTime", (String)paramObj.getString("endDateTime"));
//			whereParam.put("vehicleId", (String)paramObj.getString("vehicleId"));
//			
//			switch(alarmType){
//				/*case "totalAreaInout":
//					listVehicleAlarmDetails=alarmDailyDetailService.queryAreaInOutAlarmDailyByCondition(whereParam);
//					break; 
//				case "totalRadInout": 
//					listVehicleAlarmDetails=alarmDailyDetailService.queryRoadInOutAlarmDailyByCondition(whereParam);
//					break; 
//				case"totalLocaleInout": 
//					listVehicleAlarmDetails=alarmDailyDetailService.queryLocaleInOutAlarmDailyByCondition(whereParam);
//					break; 	*/
//				case"totalRoadOverspeed":
//					listVehicleAlarmDetails=alarmDailyDetailService.queryRoadLevelAlarmDailyByCondition(whereParam);
//					break;
//				case"totalNightDriving":
//					listVehicleAlarmDetails=alarmDailyDetailService.queryNightDrivingAlarmDailyByCondition(whereParam);
//					break;
//				case"totalVehicleSpeed": 
//					listVehicleAlarmDetails=alarmDailyDetailService.queryOverSpeedAlarmDailyByCondition(whereParam);
//					break; 
//				case"totalVehicleTired": 
//					listVehicleAlarmDetails=alarmDailyDetailService.queryTiredAlarmDailyByCondition(whereParam);
//					break; 
//				case"picCount": 
//					listVehicleAlarmDetails=hisPicService.queryPicListByVehicleId(whereParam.get("vehicleId").toString(),DateUtil.getStandardDateStr(DateUtil.getStrToDate(whereParam.get("starDateTime").toString()))+" 00:00:00" ,DateUtil.getStandardDateStr(DateUtil.getStrToDate(whereParam.get("endDateTime").toString()))+" 23:59:59" );
//					break; 
//			}
//		}
//		vehicleRunningVo.setRows(listVehicleAlarmDetails);
//		vehicleRunningVo.setTotol(listVehicleAlarmDetails.size());
//		vehicleRunningVo.setPage(1);
//		return vehicleRunningVo;
//	}
//	
//	/**
//	 * 导出报表
//	 * @return
//	 */
//	@RequestMapping(value="exportVehicleRunning.html")
//	@ResponseBody
//	public void exportVehicleRunning(HttpServletResponse response,HttpServletRequest request, String paramsGrid, String colModel,
//			String title,String imgsrc ){
//		List<String> colModelList = JSON.parseObject(colModel, List.class);
//		List<String> imgsrcList   = JSON.parseObject(imgsrc, List.class);
//		/*ParamMap param = FlexiGridUtil.parseJSONParam(paramsGrid);
//		
//		
//		Object fromRow=String.valueOf(paramMap.get("_start_row"));	//开始行
//		Object toRow=String.valueOf(paramMap.get("_end_row"));		//结束行
//*/		
//		//Map<String, Object> paramMap = FlexiGridUtil.parseJSONParam(paramsGrid).getWhereParam();
//		Map<String, Object> paramMap=getReqParameters();
//		List<AnalysisVo> result=vehicleRunningService.getVehicleRunningDetails(paramMap);
//		List<HashMap<String, String>> rows = new ArrayList<HashMap<String, String>>();
//		
//		for(AnalysisVo obj : result){
//			HashMap<String, String> map = new HashMap<String, String>();
//			
//			map.put("analyseDate", obj.getAnalyseDate());
//			map.put("totalMileage", String.valueOf(obj.getTotalMileage()));
//			map.put("duration",DateUtil.getHMBySecond(obj.getDuration()));
//			map.put("picCount", String.valueOf(obj.getPicCount()));
//			
//			map.put("totalRoadOverspeed", String.valueOf(obj.getTotalRoadOverspeed()));		
//			map.put("totalNightDriving", String.valueOf(obj.getTotalNightDriving()));
//			map.put("totalVehicleSpeed", String.valueOf(obj.getTotalVehicleSpeed()));
//			map.put("totalVehicleTired", String.valueOf(obj.getTotalVehicleTired()));
//			
//			rows.add(map);
//		}
//		
//		int index=-1;
//		List rowsList = new ArrayList<>();
//		rowsList.add(rows);
//		exportExl(request, response,title, removeHeadName(colModelList,index,-1),rowsList,imgsrcList);
//		
//		
//	}
//	
//	 
//}
